package com.huawei123.hasee.cniao5store.adapter.section;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.huawei123.hasee.cniao5store.R;
import com.huawei123.hasee.cniao5store.bean.CategoryBean;
import com.zhxu.recyclerview.base.ViewHolder;
import com.zhxu.recyclerview.section.StatelessSection;

import java.util.List;

/**
 * 项目名称：Cniao5Store
 * 类描述：分类页面除了头部与搜索栏的实现
 * 创建人：luohao
 * 创建时间：2018/2/4 16:48
 * 修改人：luohao
 * 修改时间：2018/2/4 16:48
 * 修改备注：
 */

public class CategoryContactsSection extends StatelessSection {

    private final Context context;
    private final String title;
    private final List<CategoryBean.CategoryDataBean> categoryDataBeans;

    public CategoryContactsSection(Context context, String title, List<CategoryBean.CategoryDataBean> categoryDataBeanList) {
        super(R.layout.applistitem_titlecard, R.layout.applistitem_subcat);
        this.context = context;
        this.title = title;
        this.categoryDataBeans = categoryDataBeanList;
    }

    /**
     * 内容条目
     */
    @Override
    public int getContentItemsTotal() {
        return categoryDataBeans.size();
    }

    @Override
    public ViewHolder getItemViewHolder(View view, int viewType) {
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(ViewHolder holder, int position) {
        CategoryBean.CategoryDataBean categoryDataBean = categoryDataBeans.get(position);
        holder.setImageUrl(R.id.mIV_appicon, categoryDataBean.getIconUrl());
        holder.setText(R.id.mTV_ItemTitle, categoryDataBean.getName());
    }

    class ItemViewHolder extends ViewHolder {

        ImageView appicon;
        TextView ItemTitle;

        public ItemViewHolder(View view) {
            super(context, view);
            appicon = (ImageView) view.findViewById(R.id.mIV_appicon);
            ItemTitle = (TextView) view.findViewById(R.id.mTV_ItemTitle);

        }
    }

    /**
     * 分组标题
     */

    @Override
    public ViewHolder getHeaderViewHolder(Context context, View view) {
        return new HeaderViewHolder(view);
    }

    @Override
    public void onBindHeaderViewHolder(ViewHolder holder) {
        super.onBindHeaderViewHolder(holder);
        holder.setText(R.id.mTV_ItemTitle, title);
    }

    class HeaderViewHolder extends ViewHolder {

        TextView tvTitle;
        TextView tvMore;
        ImageView ivMore;

        public HeaderViewHolder(View view) {
            super(context, view);
            tvTitle = (TextView) view.findViewById(R.id.mTV_ItemTitle);
            tvMore = (TextView) view.findViewById(R.id.mTV_downbtn);
            ivMore = (ImageView) view.findViewById(R.id.mIV_arrow_right);

            tvMore.setVisibility(View.GONE);
            ivMore.setVisibility(View.GONE);

        }

    }

}
